<?php

/**
 * winbinder 패키지 
 * 
 * 
 * @package php.ui.winbinder
 */


/**
 * WBMenu
 *
 * @package php.ui.winbinder
 */
class WBMenu extends WBControl { 

	private $menuItem = array();

	public function __construct($options = array()) { 
		$options['class'] = Menu;

		parent::__construct($options);
	}

	public function initCreate() { 
		parent::initCreate();

		if (isset($this->items)) { 
			$temp = array();
			$this->setOption('menuItem', array());

			foreach ($this->getOption('items') as $item) { 
				if (is_array($item)) { 
					$menuItem = $this->getOption('menuItem');
										
					if ($item['caption']) { 
						$item['parent'] = $this;
						$tempItem = new WBMenuItem($item);

						$temp[] = $tempItem->getMenuTemplate();
						
						$menuItem[] = $tempItem;
					} else { 
						$tempItem = new WBMenuItem(array(
							'parent'	=> $this,
							'caption'	=> $item[1],
							'hint'		=> $item[2],
							'image'		=> $item[3],
							'accel'		=> $item[4],
							'callback'	=> $item[5],
						));

						$temp[] = $tempItem->getMenuTemplate();
						
						$menuItem[] = $tempItem;
					}
					
					$this->setOption('menuItem', $menuItem);					
				} else { 
					$temp[] = $item;
				}
			}

			$this->setOption('caption', $temp);
		}
	}

	public function initComponent() { 
		parent::initComponent();

		// set enabled
		foreach ($this->getOption('menuItem') as $item) { 
			$item->initMenuItem();
		}
	}

	/**
	 * MenuItem 얻어오기
	 * 
	 * @param int $index menu array index 
	 * @return WBMenuItem
	 */
	public function getMenuItem($index = 0) {
		$menuItem = $this->getOption('menuItem'); 
		return $menuItem[$index];
	}

	/**
	 * MenuItem 리스트 얻어오기 
	 * 
	 * @return array
	 */
	public function getMenuItemList() { 
		return $this->getOption('menuItem');
	}
}

?>
